package com.lecyon.farm.common.constant;

import com.baomidou.mybatisplus.core.metadata.OrderItem;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author YaoZheng
 * 系统错误码
 */
public class CommonConstant {

    public static final String COPYRIGHT = "lnpdit@YaoZheng";

    public static final List<OrderItem> orderItemList = new ArrayList() {
        {
            add(OrderItem.desc("mt.create_date"));
        }
    };

    public static final String FILE_NAME_PREFIX = "FARM_";

    /**
     * 查询时排序字段的统一前缀
     */
    public static final String PRE_ORDER_COLUMN = "mt.";

    /**
     * 系统默认语言
     */
    public static final String DEFAULT_LANGUAGE = "zh-cn";

    /**
     * 不自动加工sql的表名前缀数组
     */
    public static final String[] TABLE_FILTER_PREFIX_LIST = new String[]{"sys_", "fm_", "js_"};

    /**
     * 不自动加工sql的表名数组
     */
    public static final String[] TABLE_FILTER_NAME_LIST = new String[]{"province", "city", "area", "street", "tenant",
            "users", "operations", "operating_record", "monitor_data",
            "equipment_parameter", "equipment_summary", "equipment_status", "equipment_status_detail",
            "package_serial_number"};

    /**
     * vo中的空值替换
     */
    public static final String NULL_EMPTY_STRING_REPLACE = "";

    public final static String REQUEST_SOURCE_ANDROID_APP = "fm_android_app";
    public final static String REQUEST_SOURCE_IOS_APP = "fm_ios_app";
    public final static String APP_ID = "FARM";
    public final static String SYSTEM_NAME = "FARM";
    public final static String SYSTEM_SPLIT_STR = "_";
    public final static String SYSTEM_TENANT_ID_FIELD = "owner";
    public final static String DEFAULT_TENANT_ID = "7DED1D939C81A42B40AE1019B4A73632";
    public final static Long DEFAULT_SYS_USER_ID = -9999L;
    public final static int MAX_LENGTH_REMARK_FIELD = 500;
    public final static int MAX_LENGTH_FIELD = 200;
    public final static int MAX_LENGTH_VERSION_FIELD = 100;
    public final static int MAX_LENGTH_DESCRIPTION_FIELD = 255;
    public final static int MAX_LENGTH_URL_FIELD = 255;
    public final static int MAX_LENGTH_BOOLEAN_FIELD = 1;
    public final static int MAX_LENGTH_DICT_FIELD = 50;
    public final static int MIN_LENGTH_FIELD = 0;
    public final static int MAX_LENGTH_ICCID = 20;
    public final static String DATE_TIME_FORMAT_PATTERN = "yyyy-MM-dd HH:mm:ss";
    public final static String DATE_FORMAT_PATTERN = "yyyy-MM-dd";
    public final static String TIME_ZONE = "GMT+8";
    public final static String DATE_TIME_FILE_NAME_FORMAT_PATTERN = "yyyyMMddHHmmss";
    public final static String DATE_FILE_NAME_FORMAT_PATTERN = "yyyyMMdd";
    public final static BigDecimal MIN_PERCENT = new BigDecimal("0");
    public final static BigDecimal MAX_PERCENT = new BigDecimal("100");
    public final static int SALT_VALUE_LENGTH = 32;
    public final static String SALT_METHOD = "MD5";
    public final static String JSON_CONVERT_ERROR_MESSAGE = "参数错误";
    public final static String DEFAULT_ADMINISTRATOR_NAME = "公司管理员";
    public final static int MAX_LENGTH_FORMAT_NUMBER_STRING = 6;
    public final static int MIN_LENGTH_FORMAT_NUMBER_STRING = 6;
    public final static int MIN_LENGTH_FORMAT_PACKAGE_SERIAL_NUMBER_STRING = 8;
    public final static Integer PACKAGE_SERIAL_NUMBER_INIT_VALUE = 1;

    /**
     * token在redis中有效的最大时长
     */
    public static final long MAX_REDIS_TOKEN_STORAGE_TIME = 60 * 60 * 24 * 7;

    /**
     * spring session 存储在redis中的最大时长
     */
    public static final int MAX_INACTIVE_INTERVAL_IN_SECONDS = 60 * 5;

    /**
     * 设备心跳标识 存储在redis中的最大时长
     */
    public static final int MAX_EQUIPMENT_ONLINE_FLAG_IN_SECONDS = 60;

    /**
     * 仓库操作类型
     * storage----入库
     * outbound------出库
     * transfer------移库
     */
    public final static String WAREHOUSE_BUSINESS_TYPE_STORAGE = "storage";
    public final static String WAREHOUSE_BUSINESS_TYPE_OUTBOUND = "outbound";
    public final static String WAREHOUSE_BUSINESS_TYPE_TRANSFER = "transfer";

    /**
     * 可以工作的最低年龄限制，低于此年龄为童工
     */
    public static final int MIN_WORK_AGE = 16;

    /**
     * 证件类型：身份证
     */
    public static final String CERTIFICATE_TYPE_IDENTITY = "identity";
    /**
     * 证件类型：护照
     */
    public static final String CERTIFICATE_TYPE_PASSPORT = "passport";
    /**
     * 证件类型：驾驶证
     */
    public static final String CERTIFICATE_TYPE_DRIVING = "driving";
    /**
     * 证件类型：暂住证
     */
    public static final String CERTIFICATE_TYPE_TEMPORARY = "temporary";

    /**
     * 系统用户默认用户类型为“普通用户”
     */
    public final static String DEFAULT_USER_TYPE = "0";

    public final static String AUTHORITY_ALL = "AUTHORITY_ALL";
    public final static String RESOURCE_TYPE_MENU = "menu";
    public final static String RESOURCE_TYPE_BTN = "button";
    public final static String EX_AUTHORITY_ERROR_MSG = "权限验证失败，请尝试重新登录";
    public final static String EX_AUTHENTICATION_ERROR_MSG = "登录验证失败";
    public final static String NULL_OBJ = "null";

    /**
     * 系统短信相关
     */
    public final static int VERIFY_CODE_LENGTH = 6;
    public final static int VERIFY_CODE_SEND_INTERVAL_MINUTES = 1;
    public final static long VERIFY_CODE_REDIS_DURATION = 10 * 60;
    public final static String SHORT_MESSAGE_SEND_SUCCESS_CODE = "OK";

    /**
     * 硬件通讯相关
     */
    public final static int HARDWARE_DEFAULT_FAN_QUANTITY = 6;
    public final static int HARDWARE_DEFAULT_UUIVERTOR_QUANTITY = 6;
    public final static BigDecimal HARDWARE_FREQUENCY_UPPER_LIMIT_DEFAULT = new BigDecimal("400");
    public final static BigDecimal HARDWARE_FREQUENCY_LOWER_LIMIT_DEFAULT = new BigDecimal("0");
    public final static String HARDWARE_REQUEST_OPERATIONS_LIST_REDIS_KEY = "hardware_request_operations_list";
    public final static String HARDWARE_RESPONSE_PREFIX = "LNPDIT";
    public final static String HARDWARE_RESPONSE_SPLIT_STR = ",";
    public final static String[] IS_DEFAULT_EQUIPMENT_TYPE_NAMES = new String[]{"gateway"};
    public final static String NUMBER_STRING_REPLACE_STR = "0";


    //    错误码定义如下：
    //    系统使用0～59999
    //    业务通用20000～29999
    //    业务自定义60000～79999
    //    设备：61000～61999
    //    仓储：62000～62999
    //    生产：70000～70999
    //    基础：71000～71999
    //    销售：72000～72999
    //    采购：73000～73999
    //    质检：74000～74999
    //    排产：75000～75999
    //    计划管理：76000～76999
    //    DNC：77000～77999 DncConstants
    /**
     * @api {get} /CommonConstants/ReturnCode/result 返回结果(100)
     * @apiGroup RETURN CODE
     * @apiParam {int} 500 系统异常 EX_OTHER
     * @apiParam {int} 200 操作成功 SUCCESS
     */
    public static final int EX_OTHER = 500;
    public static final int SUCCESS = 200;


    /**
     * @api {get} /CommonConstants/ReturnCode/authority 权限(自定义)
     * @apiGroup RETURN CODE
     * @apiParam {int} 60000 查询结果不唯一
     * @apiParam {int} 60001 没有对应的查询结果
     * @apiParam {int} 60002 数量不满足对应操作
     * @apiParam {int} 60003 关联数据查询不到
     * @apiParam {int} 60004 关联数据状态不满足当前操作
     * @apiParam {int} 60005 短信发送相关错误
     * @apiParam {int} 60006 自动生成数据条件不足
     * @apiParam {int} 60007 生产活动与任务类型不匹配
     * @apiParam {int} 60008 数据逻辑错误
     */
    public static final int TOO_MANY_RESULT_EXCEPTION = 60000;
    public static final int NO_RECORD_WITH_CONDITION = 60001;
    public static final int QUANTITY_NOT_SUFFICIENT = 60002;
    public static final int ASSOCIATED_DATA_MISS = 60003;
    public static final int ASSOCIATED_DATA_STATUS_FORBID_ACTION = 60004;
    public static final int SHORT_MESSAGE_ERROR = 60005;
    public static final int AUTO_GENERATE_CONDITION_MISS_OR_ERROR = 60006;
    public static final int PRODUCTION_ACTION_TASK_TYPE_ERROR = 60007;
    public static final int DATA_LOGIC_ERROR = 60008;

    /**
     * @api {get} /CommonConstants/ReturnCode/authority 权限(4000)
     * @apiGroup RETURN CODE
     * @apiParam {int} 40101 token异常 EX_TOKEN_ERROR
     * @apiParam {int} 40102 用户token异常 EX_USER_INVALID
     * @apiParam {int} 40131 客户端token异常 EX_CLIENT_INVALID
     * @apiParam {int} 40331 客户端无权限 EX_CLIENT_FORBIDDEN
     * @apiParam {int} 40103 台会员中心用户名密码登录失败 EX_MEMBER_LOGIN
     * @apiParam {int} 40104 平台会员中心token验证失败 EX_MEMBER_TOKEN
     * @apiParam {int} 40105 平台会员中心注册会员失败 EX_MEMBER_REGISTER
     * @apiParam {int} 40106 登出失败 EX_MEMBER_LOGOUT
     * @apiParam {int} 40107 平台会员中心用户许可验证失败 EX_LINCENSE_ERROR
     * @apiParam {int} 40108 平台会员中心用户名没有权限 EX_NOGROUP_ERROR
     * @apiParam {int} 40110 用户名或密码错误 EX_USER_LOGIN
     * @apiParam {int} 40111 租户已被禁用 EX_VALID_STATE_ERROR
     * @apiParam {int} 40112 没有找到用户 NOT_FOUND_USER
     * @apiParam {int} 40113 目标状态无效 TARGET_STATUS_ERROR
     * @apiParam {int} 40113 切换状态条件不满足 TARGET_STATUS_CONDITION_ERROR
     */
    public static final int EX_TOKEN_ERROR = 40101;
    public static final int EX_USER_INVALID = 40102;
    public static final int EX_CLIENT_INVALID = 40131;
    public static final int EX_CLIENT_FORBIDDEN = 40331;
    public static final int EX_MEMBER_LOGIN = 40103;
    public static final int EX_MEMBER_TOKEN = 40104;
    public static final int EX_MEMBER_REGISTER = 40105;
    public static final int EX_MEMBER_LOGOUT = 40106;
    public static final int EX_LICENSE_ERROR = 40107;
    public static final int EX_NOGROUP_ERROR = 40108;
    public static final int EX_USER_LOGIN = 40110;
    public static final int EX_VALID_STATE_ERROR = 40111;
    public static final int NOT_FOUND_USER = 40112;
    public static final int TARGET_STATUS_ERROR = 40113;
    public static final int SWITCH_STATUS_CONDITION_NOT_SATISFY = 40114;


    /**
     * @api {get} /CommonConstants/ReturnCode/db 数据库(6000)
     * @apiGroup RETURN CODE
     * @apiParam {int} 6001 查询错误 EX_DB_SELECT_MISS
     * @apiParam {int} 6002 非分页查询返回记录数超过最大设置 EX_MAX_QUERY_NUM
     * @apiParam {int} 6101 插入错误 EX_DB_INSERT_ERROR
     * @apiParam {int} 6201 修改出错 EX_DB_UPDATE_ERROR
     * @apiParam {int} 6202 找不到要被修改的对象  EX_DB_UPDATE_MISS
     * @apiParam {int} 6301 删除出错 EX_DB_DELETE_ERROR
     * @apiParam {int} 6302 找不到要被删除的对象 EX_DB_DELETE_MISS
     * @apiParam {int} 6303 Redis异常
     */
    public static final int EX_DB_SELECT_MISS = 6001;
    public static final int EX_MAX_QUERY_NUM = 6002;
    public static final int EX_DB_INSERT_ERROR = 6101;
    public static final int EX_DB_UPDATE_ERROR = 6201;
    public static final int EX_DB_UPDATE_MISS = 6202;
    public static final int EX_DB_DELETE_ERROR = 6301;
    public static final int EX_DB_DELETE_MISS = 6302;
    public static final int EX_DB_REDIS_ERROR = 6303;
    public static final int EX_DB_MONGO_INSERT_ERROR = 6304;

    /**
     * @api {get} /CommonConstants/ReturnCode/request 请求(8000)
     * @apiGroup RETURN CODE
     * @apiParam {int} 8001 请求参数错误 EX_REQUEST_PARAM_ERROR
     * @apiParam {int} 8002 编号重复 EX_FORM_VALIDATE_UNIQUE
     * @apiParam {int} 8003 必填项 EX_FORM_VALIDATE_REQUIRED
     * @apiParam {int} 8004 关联ID重复 EX_FORM_VALIDATE_ID_UNIQUE
     * @apiParam {int} 8005 状态不符合要求 EX_FORM_VALIDATE_STATUS_ERROR
     * @apiParam {int} 8006 不在有效时间范围内 EX_FORM_DATE_NOT_VALID_ERROR
     * @apiParam {int} 8007 获取文件上传相关参数 EX_REQUEST_UPLOAD_PARAM_ERROR
     * @apiParam {int} 8008 无法通过租户找到公司 EX_REQUEST_OWNER_COMPANY_NONEXISTENCE_ERROR
     * @apiParam {int} 8009 版本重复 EX_FORM_VALIDATE_VERSION_ERROR
     * @apiParam {int} 8010 生成编号失败 EX_FORM_GET_NUMBER_ERROR
     * @apiParam {int} 8011 授权码错误 EX_FORM_GET_NUMBER_ERROR
     * @apiParam {int} 8012 日期格式化错误 EX_DATE_FORMAT_ERROR
     * @apiParam {int} 8013 日期解析错误 EX_DATE_PARSE_ERROR
     */
    public static final int EX_REQUEST_PARAM_ERROR = 8001;
    public static final int EX_FORM_VALIDATE_ERROR = 8001;
    public static final int EX_FORM_VALIDATE_UNIQUE = 8002;
    public static final int EX_FORM_VALIDATE_REQUIRED = 8003;
    public static final int EX_FORM_VALIDATE_ID_UNIQUE = 8004;
    public static final int EX_FORM_VALIDATE_STATUS_ERROR = 8005;
    public static final int EX_FORM_DATE_NOT_VALID_ERROR = 8006;
    public static final int EX_REQUEST_UPLOAD_PARAM_ERROR = 8007;
    public static final int EX_REQUEST_OWNER_COMPANY_NONEXISTENCE_ERROR = 8008;
    public static final int EX_FORM_VALIDATE_VERSION_ERROR = 8009;
    public static final int EX_FORM_GET_NUMBER_ERROR = 8010;
    public static final int EX_FORM_AUTHCODE_ERROR = 8011;
    public static final int EX_DATE_FORMAT_ERROR = 8012;
    public static final int EX_DATE_PARSE_ERROR = 8013;
    public static final int PRODUCT_TECHNOLOGY_VALIDATE_UNIQUE = 8014;
    public static final int WORK_CENTER_ID_NOT_VALIDATE = 8015;

    /**
     * @api {get} /CommonConstants/ReturnCode/file 文件(9000)
     * @apiGroup RETURN CODE
     * @apiParam {int} 9001 请求七牛TOKEN出错 EX_GET_QINIU_TOKEN
     * @apiParam {int} 9002 请求SEAFILE Token出错 EX_GET_SEAFILE_URL
     * @apiParam {int} 9003 excel相关错误 EX_EXCEL_ERROR
     * @apiParam {int} 9004 模板不能为空 EX_EXCEL_TEMPLATE_EMPTY
     * @apiParam {int} 9005 excel文件不能为空 EX_EXCEL_FILE_EMPTY
     */
    public static final int EX_GET_QINIU_TOKEN = 9001;
    public static final int EX_GET_SEAFILE_URL = 9002;
    public static final int EX_EXCEL_ERROR = 9003;
    public static final int EX_EXCEL_TEMPLATE_EMPTY = 9004;
    public static final int EX_EXCEL_FILE_EMPTY = 9005;

    /**
     * @api {get} /CommonConstants/Constant/context 上下文
     * @apiGroup CONSTANT
     * @apiParam {String} currentUserId CONTEXT_KEY_USER_ID
     * @apiParam {String} currentUserName CONTEXT_KEY_USERNAME
     * @apiParam {String} currentUser CONTEXT_KEY_USER_NAME
     * @apiParam {String} currentUserToken CONTEXT_KEY_USER_TOKEN
     * @apiParam {String} name JWT_KEY_NAME
     */
    public static final String CONTEXT_KEY_USER_ID = "currentUserId";
    public static final String CONTEXT_KEY_USERNAME = "currentUserName";
    public static final String CONTEXT_KEY_USER = "currentUser";
    public static final String CONTEXT_KEY_OWNER = "currentOwner";
    public static final String CONTEXT_KEY_USER_ROLES = "currentUserRoles";
    public static final String CONTEXT_KEY_USER_TOKEN = "currentUserToken";
    public static final String JWT_KEY_USER_ID = "userId";
    public static final String JWT_KEY_NAME = "name";

    /**
     * @api {get} /CommonConstants/Constant/db 数据库
     * @apiGroup CONSTANT
     * @apiParam {int} 1000 非分页查询返回结果最大条目数量 MAX_QUERY_NUM
     * @apiParam {String} 0 删除标记-未删除 DEL_FLAG_UNDELETED
     * @apiParam {String} 1 删除标记-已删除 DEL_FLAG_UNDELETED
     * @apiParam {String} 3 删除标记-中间状态 DEL_FLAG_INTERMEDIATE
     * @apiParam {String} 0 否 WHETHER_FALSE
     * @apiParam {String} 1 是 WHETHER_TRUE
     */
    public static final int MAX_QUERY_NUM = 1000;
    public static final String DEL_FLAG_UNDELETED = "0";
    public static final String DEL_FLAG_DELETED = "1";
    public static final String DEL_FLAG_INTERMEDIATE = "3";
    public static final String WHETHER_FALSE = "0";
    public static final String WHETHER_TRUE = "1";

    /**
     * @api {get} /CommonConstants/Constant/sequence 序列
     * @apiGroup CONSTANT
     * @apiParam {int} 0 默认序列 SEQUENCE_DEFAULT
     * @apiParam {int} 1 租户自定义序列 SEQUENCE_OWNER
     * @apiParam {String} wis:sequence WIS序列存储空间 WIS_SEQUENCE_NAMESPACE
     */
    public static final int SEQUENCE_DEFAULT = 1;
    public static final int SEQUENCE_OWNER = 1;
    public static final String SEQUENCE_TYPE_VALUE = "value";
    public static final String SEQUENCE_TYPE_CACHE = "cache";

}
